<template>
	<view class="home-page page">
		<!-- 头部组件 -->
		<custom-nav-bar title='推荐'></custom-nav-bar>
		<!-- 轮播图 -->
		<view class="banner">
			<swiper indicator-dots circular indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff"
				autoplay :interval="3000" :duration="1000">
				<swiper-item v-for="item in bannerList" :key="item._id">
					<image :src="item.picurl" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 公告 -->
		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="25"></uni-icons>
				<text class="text">公告:</text>
			</view>
			<view class="center">
				<swiper vertical autoplay interval="1500" duration="300" circular>
					<swiper-item v-for="item in news" :key="item._id">
						{{item.title}}
					</swiper-item>
				</swiper>
			</view>
			<view class="right">

				<uni-icons type="right" size="16"></uni-icons>
			</view>
		</view>
		<!-- 每日推荐 -->
		<view class="recommend">
			<common-title>
				<template #name>
					每日推荐
				</template>
				<template #custom>
					<view class="date">
						<uni-icons type="calendar" size="20" color="#28b389"></uni-icons>
						<view class="text">
							<uni-dateformat :date="Date.now()" format="yyyy年MM月dd日"></uni-dateformat>
						</view>
					</view>
				</template>
			</common-title>
			<view class="content">
				<scroll-view :scroll-x='true'>
					<view class="box" v-for="item in dayRandoms" @click="goPreview">

						<image :src="item.smallPicurl" mode="aspectFill"></image>

					</view>
				</scroll-view>
			</view>
		</view>
		<!-- 专题 -->
		<view class="special">
			<common-title>
				<template #name>
					专题精选
				</template>
				<template #custom>

					<view class="more">
						<navigator url="/pages/category_list/category_list" class="more">
							More+
						</navigator>
					</view>
				</template>
			</common-title>
			<view class="content">
				<special-item v-for="item in classfiy" :item='item' :key="item._id"></special-item>
				<special-item isMore></special-item>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		getBanners,
		getDayRandom,
		getNews,
		getCategories
	} from '../../api/api';
	const bannerList = ref([])
	const dayRandoms = ref([])
	const news = ref([])
	const classfiy = ref([])
	const getBanner = async () => {
		let res = await getBanners()
		bannerList.value = res.data
	}
	const getDayRandoms = async () => {
		let res = await getDayRandom()
		dayRandoms.value = res.data
	}
	const getNewsList = async () => {
		let res = await getNews({
			select: true
		})
		news.value = res.data
	}
	const getCategory = async () => {
		const res = await getCategories({
			select: true
		})
		classfiy.value = res.data
	}
	const goPreview = () => {
		uni.navigateTo({
			url: '/pages/preview/preview'
		})
	}
	getNewsList()
	getBanner()
	getDayRandoms()
	getCategory()
</script>

<style lang="scss" scoped>
	.home-page {
		.banner {
			width: 100%;
			padding: 30rpx 0;

			swiper {
				width: 100%;
				height: 340rpx;

				&-item {
					padding: 0 30rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}
			}
		}

		.notice {
			width: 690rpx;
			height: 80rpx;
			background-color: #f9f9f9;
			line-height: 80rpx;
			margin: 0 auto;
			border-radius: 80rpx;
			display: flex;

			.left {
				width: 140rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				:deep() {
					.uni-icons {
						color: $brand-theme-color !important;
					}

				}

				.text {
					color: $brand-theme-color;
					font-weight: bold;
					font-size: 28rpx;

				}
			}

			.center {
				flex: 1;
				padding: 0 20rpx;

				swiper {
					height: 100%;

					&-item {
						height: 100%;
						font-size: 30rpx;
						color: #666;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}
			}

			.right {
				display: flex;
				align-items: center;
				justify-content: center;

				width: 70rpx;

				:deep() {
					.uni-icons {
						color: $brand-theme-color !important;
					}

				}
			}
		}

		.recommend {
			padding-top: 50rpx;

			.date {

				color: $brand-theme-color;
				display: flex;
				align-items: center;

				:deep() {
					.uni-icons {
						color: $brand-theme-color !important;
					}

				}

				.text {
					margin-left: 10rpx;
				}
			}

			.content {
				width: 720rpx;
				margin-left: 30rpx;
				margin-top: 30rpx;

				scroll-view {
					white-space: nowrap;

					.box {
						width: 200rpx;
						height: 430rpx;
						display: inline-block;
						margin-right: 15rpx;

						image {
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}

					.box:last-child {
						margin-right: 30rpx;
					}
				}
			}
		}

		.special {
			padding: 50rpx 0;

			.more {
				font-size: 28rpx;
				color: #666;
				margin-right: 20rpx;
			}

			.content {
				margin-top: 30rpx;
				padding: 0 30rpx;
				display: grid;
				grid-template-columns: repeat(3, 1fr);
				grid-gap: 15rpx;

				.special-item {
					// margin-bottom: 30rpx;
				}


			}
		}
	}
</style>